package com.jeedle.nahe;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.widget.Toast;

public class WebViewer extends Activity {

	private static final String HTML_CONTENT = "com.jeedle.nahe.HTMLCONTENT";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_web_viewer);
		this.loadHTML();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.web_viewer, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    switch (item.getItemId()) {
		    case R.id.return_to_editor:
		        this.returnToEditor();
		        return true;
		    default:
		        return super.onOptionsItemSelected(item);
	    }
	}
	
	private void returnToEditor(){
		this.finish();
	}
	
	private void loadHTML(){
		Intent intent = getIntent();
		if(intent != null){
			String htmlContent = intent.getStringExtra(HTML_CONTENT);
			WebView myWebView = (WebView) findViewById(R.id.web_viewer);
			myWebView.loadData(htmlContent, "text/html", "UTF8");
		}
		else
		{
			Context context = getApplicationContext();
			CharSequence text = "HTML content could not be loaded";
			int duration = Toast.LENGTH_SHORT;
			Toast toast = Toast.makeText(context, text, duration);
			toast.show();
		}
	}



	
}
